package com.gator.desig_mode.translate;

import java.util.List;

/**
 * @author 何章怀晓 hezhanghuaixiao
 * @version V1.0
 * @desc 被保存某些状态的对象
 */
public class Originator {

  private String name;

  private float aggressivity;//攻击力

  private float defensivePower;//防御力

  private int index;//最终确定需要恢复的对象，可能是恢复到上一个，可能是恢复到初始，此参数控制


  //确定要保存的状态，可能只是部分属性
  public Memento saveStatus(Caretaker caretaker) {
    Memento memento = new Memento();
    memento.setAggressivity(aggressivity);
    memento.setDefensivePower(defensivePower);
    memento.setName(name);
    //将状态保存到集合中
    int index = caretaker.add(memento);
    //下标替换为最新的（即添加备忘录次数-1为index）
    //这里可根据需求灵活设置，如恢复到初始状态/恢复到上次状态
    //将保存在Caretaker中的对象下标和当前下标对应
    this.index = index;
    return memento;
  }


  //恢复状态
  public void restoreState(Memento memento) {
    this.name = memento.getName();
    this.aggressivity = memento.getAggressivity();
    this.defensivePower = memento.getDefensivePower();
    this.index = memento.getIndex();
  }


  public Originator(String name, float aggressivity, float defensivePower) {
    this.name = name;
    this.aggressivity = aggressivity;
    this.defensivePower = defensivePower;
  }

  public Originator() {
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public float getAggressivity() {
    return aggressivity;
  }

  public void setAggressivity(float aggressivity) {
    this.aggressivity = aggressivity;
  }

  public float getDefensivePower() {
    return defensivePower;
  }

  public void setDefensivePower(float defensivePower) {
    this.defensivePower = defensivePower;
  }

  @Override
  public String toString() {
    return "Originator{" +
        "name='" + name + '\'' +
        ", aggressivity=" + aggressivity +
        ", defensivePower=" + defensivePower +
        '}';
  }

  public int getIndex() {
    return index;
  }

  public void setIndex(int index) {
    this.index = index;
  }

}
